package thread.ch05;

import java.util.HashSet;
import java.util.Random;
import java.util.Set;

import thread.annotation.GuardBy;

/**
 * 迭代隐藏在字符串拼接中（不要这样做）
 * @author Edgar Zhang
 *
 */
public class HiddenIterator {

	@GuardBy("this")
	private final Set<Integer> set = new HashSet<Integer>();
	
	public synchronized void add(Integer i) {
		set.add(i);
	}
	
	public synchronized void remove(Integer i) {
		set.remove(i);
	}
	
	public void addTenThings() {
		Random r = new Random();
		for (int i = 0; i < 10; i ++) {
			add(r.nextInt());
		}
		System.out.println("DEBUG: added ten elements to " + set);
	}
}
